package com.first;

import java.util.Arrays;
import java.util.Random;

/**
 * Author Name: Justice
 * Project Name: Stage11
 * File Name: ChooseSome
 * Package Name: com
 * Date: 2020-03-25 21:51
 * Copyright (c) 2020,All Rights Reserved.
 */


public class ChooseSome {
    public static void main(String[] args) {
        int[] src = new int[100];
        for (int i = 0; i < 100; i++) {
            src[i] = i * 10;
        }
        int[] target = new int[10];
        choose(src, target);
        System.out.println(Arrays.toString(src));
        System.out.println(Arrays.toString(target));
    }

    private static void choose(int[] src, int[] target) {
        Random r = new Random();
        int t = target.length;
        int s = src.length;
        int index = -1;

        for (int i = 0; i < t; i++) {
            index = r.nextInt(s - 1 - i);
            target[i] = src[index];

            int temp = src[index];
            src[index] = src[s - i - 1];
            src[s - i - 1] = temp;
        }
        Arrays.sort(src);
        Arrays.sort(target);
    }
}
